package net.sf.rose.business.bean.base;

import java.util.ArrayList;
import java.util.List;

import org.simpleframework.xml.Element;
import org.simpleframework.xml.ElementList;

/**
 * 功能：
 * 
 * @author fengjian
 * @since 2013/10/15
 */
public class Group {

	/** 工作组编号 */
	@Element
	private String id = "";

	/** 工作组名称 */
	@Element
	private String text = "";

	/** 工作组代码 */
	@Element(required = false)
	private String code = null;

	/** 子分类编号序号 最大值是999，最小值为1 */
	@Element
	private int count = 0;

	/** 子工作组序列 */
	@ElementList(required = false)
	private List<Group> childGroup = null;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public int getCount() {
		return count;
	}

	public void setCount(int count) {
		this.count = count;
	}

	public List<Group> getChildGroup() {
		if (childGroup == null) {
			childGroup = new ArrayList<Group>();
		}
		return childGroup;
	}

	public void setChildGroup(List<Group> childGroup) {
		this.childGroup = childGroup;
	}

	public void addChildGroup(Group data) {
		if (childGroup == null) {
			childGroup = new ArrayList<Group>();
		}
		count++;
		if (count < 10) {
			data.setId("00" + count);
		} else if (count < 100) {
			data.setId("0" + count);
		} else {
			data.setId(count + "");
		}
		data.setId(this.id + data.getId());
		childGroup.add(data);
	}
	
	public boolean removeChildGroup(String groupID) {
		if (childGroup == null) {
			return false;
		}
		for (int i = 0; i < childGroup.size(); i++) {
			Group child = childGroup.get(i);
			if (child.getId().equals(groupID)) {
				childGroup.remove(i);
				return true;
			}
		}
		return false;
	}

	public void update(Group group){
		this.id = group.id;
		this.code = group.code;
		this.text = group.text;
	}
}
